package com.ztsoft.user.controller.project;

import com.ztsoft.user.pojo.entity.project.AnswerQuote;
import com.ztsoft.user.service.project.AnswerQuoteService;
import com.ztsoft.user.utils.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Slf4j
@CrossOrigin("*")
@RestController
@RequestMapping("/answerQuote")
@Api(tags = "物资清单控制层")
public class AnswerQuoteController {

    @Resource
    private AnswerQuoteService answerQuoteService;

    /**
     * 上传报价汇总表
     *
     * @param pid  项目id
     * @param file 文件列表
     * @return 响应结果
     */
    @PostMapping("/answerQuoteAnalysis/{pid}")
    public Result<Object> answerQuoteAnalysis(@PathVariable("pid") String pid, @RequestBody MultipartFile file) {
        return answerQuoteService.parseUpLoadFile(pid, file);
    }

    /**
     * 左侧树
     */
    @GetMapping("/querySubcontractedTree/{pid}")
    public Result<Object> querySubcontractedTree(@PathVariable("pid") String pid) {
        return answerQuoteService.querySubcontractedTree(pid);
    }

    /**
     * 查询右侧物资清单
     *
     * @param pid 项目id
     */
    @GetMapping("/querySubcontractedAll/{pageSize}/{currentPage}/{pid}")
    public Result<Object> querySubcontractedAll(@PathVariable("currentPage") Integer currentPage,
                                                @PathVariable("pageSize") Integer pageSize,
                                                @PathVariable("pid") String pid,
                                                @RequestParam(value = "companyName", required = false) String companyName,
                                                @RequestParam(value = "projectUnit", required = false) String projectUnit,
                                                @RequestParam(value = "subcontract", required = false) String subcontract,
                                                @RequestParam(value = "subcontracted", required = false) String subcontracted,
                                                @RequestParam(value = "packageName", required = false) String packageName) {
        return answerQuoteService.querySubcontractedAll(currentPage, pageSize, pid, companyName, projectUnit, subcontract, subcontracted, packageName);
    }

    /**
     * 用户-物资查询物资树
     */
    @GetMapping("/queryAnswerQuoteTree/{pid}/{userId}")
    public Result<Object> queryAnswerQuoteTree(@PathVariable("pid") String pid,
                                               @PathVariable("userId") String userId) {
        return answerQuoteService.queryAnswerQuoteTree(pid, userId);
    }

    /**
     * 修改额度
     */
    @PutMapping("/updateAnswerQuote")
    public Result<Object> updateAnswerQuote(@RequestBody AnswerQuote answerQuote) {
        return answerQuoteService.updateAnswerQuote(answerQuote);
    }

}